/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-08-14
 * Time: 7:48
 */
public class Test78 {
//
//    public static int maxProfit(int[] prices) {
//        int n  = prices.length;
//        int[][] dp = new int[n][2];
//        // dp[i][0] 第i天是持有 dp[i][1] 不持有
//        dp[0][0] = -prices[0];
//        dp[0][1] = 0;
//        for(int i = 1; i < n; i++) {
//            dp[i][0] = Mat
//            h.max(dp[i-1][0],-prices[i]);
//            dp[i][1] = Math.max(dp[i-1][1],dp[i-1][0]+prices[i]);
//        }
//        return dp[n-1][1];
//    }

    public static int maxProfit(int[] prices) {
        int n  = prices.length;
        int ret = 0;
        for(int i = 0,priceMin = Integer.MAX_VALUE; i < n; i++) {
            ret = Math.max(ret,prices[i]-priceMin);
            priceMin = Math.min(priceMin,prices[i]);
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] num = {7,1,5,3,6,4};
        int ret = maxProfit(num);
        System.out.println(ret);
    }
}
